package reduce.fz.com.reduce.adapter;

import android.content.Context;
import android.media.Image;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;

import java.util.ArrayList;
import java.util.List;

import reduce.fz.com.reduce.R;
import reduce.fz.com.reduce.bean.Card;
import reduce.fz.com.reduce.bean.User;
import reduce.fz.com.reduce.custom.HeaderFooterStatusRecyclerViewAdapter;
import reduce.fz.com.reduce.util.PicassoUtil;

/**
 * Created by qingshengzheng on 15/8/4.
 */
public class SelfCenterAdapter extends HeaderFooterStatusRecyclerViewAdapter<AbstractRecycleHolder> {
    private User user=new User();
    private List<Card> card;
    private Context mContext;

    public SelfCenterAdapter(Context context)
    {
        card=new ArrayList<Card>();
        for(int i=0;i<11;i++)
        {
            card.add(new Card());
        }
        this.mContext=context;
    }
    @Override
    public AbstractRecycleHolder createFooterStatusViewHolder(View footerView) {
        return new AbstractRecycleHolder(footerView) {
            @Override
            public void renderView(Object bean) {

            }

            @Override
            public void initView() {

            }
        };
    }

    @Override
    protected int getHeaderItemCount() {
        return 1;
    }

    @Override
    protected int getContentItemCount() {
        return card.size();
    }

    public static class HeaderViewHolder extends AbstractRecycleHolder<User> {
        private ImageView userHeader;
        private TextView userNickName;

        public HeaderViewHolder(View itemView, RecyclerView.Adapter adapter) {
            super(itemView, adapter);
        }

        @Override
        public void renderView(User bean) {
            // PicassoUtil.laodUrl(itemView.getContext(), bean.getHeadurl(), userHeader);
            //userNickName.setText(bean.getName());
            //numPub.setText(bean.getUserDynamic().getJointeams() + "");
            //joinDate.setText(bean.getUserDynamic().getJointeams() + "");


        }

        @Override
        public void initView() {
            userHeader = (ImageView) itemView.findViewById(R.id.user_header);
            userNickName = (TextView) itemView.findViewById(R.id.tv_user_nickname);
            //numPub = (TextView) itemView.findViewById(R.id.tv_user_pub);
            //joinDate = (TextView) itemView.findViewById(R.id.tv_user_join_time);
        }
    }

    public static class MyContentViewHolder extends AbstractRecycleHolder<Card> {
        private ImageView card_image;

        public MyContentViewHolder(View itemView, RecyclerView.Adapter adapter) {
            super(itemView, adapter);
        }

        @Override
        public void renderView(Card bean) {
            Picasso.with(itemView.getContext()).load(R.drawable.paobu).into(card_image);


        }

        @Override
        public void initView() {
            card_image = (ImageView) itemView.findViewById(R.id.card_image);

        }
    }


    @Override
    protected AbstractRecycleHolder onCreateHeaderItemViewHolder(ViewGroup parent, int headerViewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.view_selfcenter_header, null);
        return new HeaderViewHolder(view, this);
    }

    @Override
    protected AbstractRecycleHolder onCreateContentItemViewHolder(ViewGroup parent, int contentViewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.layout_witness_card, null);
        return new MyContentViewHolder(view, this);
    }

    @Override
    protected void onBindHeaderItemViewHolder(AbstractRecycleHolder headerViewHolder, int position) {
        headerViewHolder.renderView(user);

    }

    @Override
    protected void onBindContentItemViewHolder(AbstractRecycleHolder contentViewHolder, int position) {
        contentViewHolder.renderView(card.get(position));

    }

    public int getSpanSize(int position) {
        if (user != null && position == 0) {
            return 2;
        } else {
            return 1;
        }
    }

    public int getSpanIndex(int position, int spanCount) {
        if (user != null && position == 0) {
            return 0;
        } else {
            return (position - 1) % spanCount;
        }
    }
}
